package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.entity.Menu;
import com.sangeng.domain.vo.MenuVo;
import com.sangeng.domain.vo.PageVo;
import com.sangeng.service.MenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("system/menu")
public class MenuController {
    private final MenuService menuService;

    @GetMapping("/list")
    public ResponseResult<List<MenuVo>> getMenuList( String menuName, String status) {
        return menuService.getMenuList(menuName, status);
    }

    @GetMapping("/listAllMenu")
    public ResponseResult<List<MenuVo>> listAllMenu(){
        return menuService.getAllMenuList();
    }

    @PostMapping
    public ResponseResult<String> addMenu(@RequestBody @Validated Menu menuDto) {
        return menuService.addMenu(menuDto);
    }

    //修改分类 先获取数据 然后修改的时候自动填充到那个框上
    @GetMapping("/{id}")
    public ResponseResult<MenuVo>  getMenu(@PathVariable Long id) {
        return menuService.getMenuById(id);
    }
    @PutMapping
    public ResponseResult<String> updateMenu(@RequestBody Menu menuDto) {
        return menuService.updateMenu(menuDto);
    }

    //多选删除
    @DeleteMapping("/{idList}")
    public ResponseResult<String> deleteMenu(@PathVariable List<Long> idList) {
        return menuService.deleteMenuById(idList);
    }
}
